--select sum(qty) from pos_return_dtl where note_no in( 'RNTPKK000649', 'RNTPKK000650', 'RNTPKK000651') and sku = '6952051827331'
--select * from pos_return_hdr where note_no in( 'RNTPKK000649', 'RNTPKK000650', 'RNTPKK000651') 
--select * from pos_return_constr where note_no = 'RNTPKK000649' order by rec_qty
--select * from pos_return_rec where note_no = 'RNTPKK000649'  
--select * from fg_st_ctrl where sku = '6952051827331'
--update receive qty
/*
update pos_return_rec set qty = a.qty 
from pos_return_dtl a
where a.note_no = pos_return_rec.note_no and 
		a.sku = pos_return_rec.sku and 
	a.note_no in('HKLPSN001040 ')
 
*/

--insert into pick
begin tran

	select sku, sum(qty) qty into #temp_iss
	from pos_return_dtl 
	where note_no in('HKLPSN001040')
	group by sku

	declare @sku nvarchar(30), @qty int, @data nvarchar(100)
	declare cu cursor  for select sku, qty from #temp_iss
	open cu
	fetch cu into @sku, @qty
	while @@fetch_status = 0
	begin
		select @data = @sku+'@@'+convert(nvarchar, @qty)
		exec sp_fg_pack_iss_dtl_save N'KO-IS0078727',N'001',N'',@data, 'R'
		fetch cu into @sku, @qty
	end
	close cu
	deallocate cu
--update fg_pick_hdr set status = 'I' where fg_pick_no = 'KO-IS0020344'
--select * from fg_trx_hdr where pick_no = 'KO-IS0020344'
 
rollback tran
